package com.qifenqian.turbot.module.presenter

import android.content.Context
import com.qifenqian.turbot.base.BasePresenter
import com.qifenqian.turbot.module.contract.RestaurantServiceContract
import com.qifenqian.turbot.module.entity.request.ServiceRequest
import com.qifenqian.turbot.module.entity.response.restaurant.RestaurantServiceEntity
import com.qifenqian.turbot.module.model.RestaurantServiceModel
import com.qifenqian.turbot.net.ModelCallback

/**
 * @author H
 * @createTime 2018/12/26 15:48
 * @description
 * @see
 * @since
 */
class RestaurantServicePresenter(context: Context, view: RestaurantServiceContract.View) : BasePresenter<RestaurantServiceContract.View, RestaurantServiceModel>(context, view), RestaurantServiceContract.Presenter {

    override fun chooseService(request: ServiceRequest) {
        mModel.chooseService(request, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.chooseServiceResult(true, msg = msg)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.chooseServiceResult(false, code, msg)
            }
        })
    }

    override fun deleteService(serviceId: Int) {
        mModel.deleteService(serviceId, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.deleteServiceResult(true, msg = msg)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.deleteServiceResult(false, code, msg)
            }
        })
    }

    override fun addService(serviceName: String) {
        mModel.addService(serviceName, object : ModelCallback<RestaurantServiceEntity> {
            override fun onSuccess(msg: String?, t: RestaurantServiceEntity?) {
                mView?.addServiceResult(true, msg = msg, restaurantServiceEntity = t, serviceName = serviceName)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.addServiceResult(false, code, msg)
            }
        })
    }

    override fun createModel(): RestaurantServiceModel {
        return RestaurantServiceModel(mContext)
    }

    override fun getServiceList() {
        mModel.getServiceList(object : ModelCallback<List<RestaurantServiceEntity>> {
            override fun onSuccess(msg: String?, t: List<RestaurantServiceEntity>?) {
                mView?.getServiceListResult(true, msg = msg, restaurantServiceEntities = t)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.getServiceListResult(false, code, msg)
            }
        })
    }
}
